<template>
	<view>
		<view class="search-box">
		  <my-search @goSearch="goSearch"></my-search>
		</view>
		<swiper :indicator-dots="true" :autoplay="true" :interval="3000" :duration="1000" :circular="true">
			<swiper-item v-for="(item,index) in swiperList" :key="index">
				<view class="swiper-item">
					<navigator :url="'/subpkg/goods_detail/goods_detail?goods_id='+item.goods_id">
						<image :src="item.image_src" mode=""></image>
					</navigator>
				</view>
			</swiper-item>
		</swiper>
		<!-- 导航列表 -->
		<view class="nav-list">
			<view class="nav-list-item" v-for="(item,index) in navList" :key="index" @click="navClickHandler(item)">
				<image :src="item.image_src" mode=""></image>
			</view>
		</view>
		<!-- 商品楼 -->
		<view class="floor-list">
			<view class="floor-item" v-for="(item,i) in floorList" :key="i">
				<view>
					<image :src="item.floor_title.image_src" class="floor-title" mode=""></image>
				</view>
				<!-- 楼层 -->
				<!-- 楼层图片区域 -->
				<view class="floor-img-box">
				  <!-- 左侧大图片的盒子 -->
				  <view class="left-img-box">
				  	<navigator :url="item.product_list[0].url">
				  	  <image :src="item.product_list[0].image_src" :style="{width: item.product_list[0].image_width + 'rpx'}" mode="widthFix"></image>
				  	</navigator>
				  </view>
				  <!-- 右侧 4 个小图片的盒子 -->
				  <view class="right-img-box">
				    <view class="right-img-item" v-for="(item2, i2) in item.product_list" :key="i2" v-if="i2 !== 0">
				      <navigator :url="item2.url">
						  <image :src="item2.image_src" mode="widthFix" :style="{width: item2.image_width + 'rpx'}"></image>
					  </navigator>
				    </view>
				  </view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import tabbar from '@/mixins/tabbar-badge.js'
	export default {
		mixins:[tabbar],
		data() {
			return {
				swiperList:[],
				navList:[],
				// 楼层数据
				floorList:[]
			}
		},
		onLoad(){
			this.getSwiperList()
			this.getNavList()
			this.getFloorList()
		},
		methods:{
			async getSwiperList(){
				const {data:res} = await uni.$http.get('/api/public/v1/home/swiperdata')
				// console.log(res)
				if(res.meta.status !==200) {
					return	uni.showToast({
						title:'请求轮播图失败！',
						duration:1500,
						icon:"none"
					})
				}
				this.swiperList = res.message
			},
			// 获取导航列表
			async getNavList(){
				const {data:res} = await uni.$http.get('/api/public/v1/home/catitems')
				// console.log('导航列表的数据',res);
				if(res.meta.status !== 200) return uni.$showMsg()
				this.navList = res.message
			},
			// 点击第一项给分类
			navClickHandler(item){
				if(item.name=='分类'){
					uni.switchTab({
						url:'/pages/cate/cate'
					})
				}
			},
			// 获取楼层的数据
			async	getFloorList(){
				const {data:res} = await uni.$http.get('/api/public/v1/home/floordata')
				// console.log('楼层数据',res);
				// 对楼层的数据进行加工
				if(res.meta.status !==200) return uni.$showMsg()
				res.message.forEach(item=>{
					item.product_list.forEach(i=>{
						i.url = '/subpkg/goods_list/goods_list?'+i.navigator_url.split('?')[1]
					})
				})
				this.floorList = res.message
				console.log('加工过的数据',this.floorList);
			},
			goSearch(){
				uni.navigateTo({
					url:'/subpkg/search/search'
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
swiper {
	height: 330rpx;
}
.search-box {
	position: sticky;
	top: 0px;
	z-index: 99;
}
.swiper-item,navigator,image{
	height: 100%;
	width: 100%;
}
// 导航栏数据
.nav-list {
	display: flex;
	flex: 1;
	justify-content: center;
	align-items: center;
	width: 100%;
	height: 100px;
}
.nav-list-item {
	display: flex;
	align-items: center;
	justify-content: center;
	text-align: center;
	width: 25%;
	height: 100%;
	image {
		width: 60%;
		height: 60%;
	}
}
.floor-title {
	height: 60px;
	width: 100%;
	display: flex;
}
.right-img-box {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-around;
}

.floor-img-box {
  display: flex;
  padding-left: 10rpx;
}
</style>
